using UnityEngine;

namespace Exploder.Demo
{
	public class DemoSelfExplode : MonoBehaviour
	{
		public Camera Camera;

		private void Start()
		{
			Application.targetFrameRate = 60;
			if (!Camera)
			{
				Camera = Camera.main;
			}
		}

		private bool IsExplodable(GameObject obj)
		{
			return obj.CompareTag(ExploderObject.Tag);
		}

		private void Update()
		{
			if (!Input.GetMouseButtonDown(0) && !Input.GetMouseButtonDown(1))
			{
				return;
			}
			Ray ray = (!Camera) ? Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition) : Camera.ScreenPointToRay(UnityEngine.Input.mousePosition);
			if (Physics.Raycast(ray, out RaycastHit hitInfo))
			{
				GameObject gameObject = hitInfo.collider.gameObject;
				if (IsExplodable(gameObject) && Input.GetMouseButtonDown(0))
				{
					ExplodeObject(gameObject);
				}
			}
		}

		private void ExplodeObject(GameObject obj)
		{
			ExploderObject component = obj.GetComponent<ExploderObject>();
			if ((bool)component)
			{
				component.ExplodeRadius(OnExplosion);
			}
		}

		private void OnExplosion(float time, ExploderObject.ExplosionState state)
		{
			if (state != ExploderObject.ExplosionState.ExplosionFinished)
			{
			}
		}
	}
}
